<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="_header_include::frag(~{::title},~{},~{})">
    <title>后台管理系统</title>
    <style>
        button a{color:#fff!important;}
    </style>
</head>
<body>
<div id="clueManage" class="clueManage mainPadding" style="display: none;">  
    <el-breadcrumb separator="/" class="elBreadcrumb marginB20">
        <el-breadcrumb-item>Home</el-breadcrumb-item>
        <el-breadcrumb-item>商务管理</el-breadcrumb-item>
        <el-breadcrumb-item>待分配邀约来访</el-breadcrumb-item>
    </el-breadcrumb>
    
    <el-row class="marginB20">
    		<shiro:hasPermission name="business:busAllocationManager:allocation">
		        <el-button type="primary" @click="toAllocationClue">分发资源</el-button>
		    </shiro:hasPermission>
    		<shiro:hasPermission name="business:busAllocationManager:allocation">
		        <el-button type="success" @click="toTransferClue">外调经理</el-button>
		    </shiro:hasPermission>
		    <shiro:hasPermission name="business:busAllocationManager:cancel">
		      <el-button type="info" @click="openCancelForm">标记取消</el-button>
		    </shiro:hasPermission>
	  </el-row>
    <div class="mainSearchBg">        
        <div class="mainSearchFormBox">
        	  <el-form :inline="true" :model="searchForm" class="demo-form-inline mainSearchForm" ref="searchForm"> 
                <el-form-item label="提交邀约时间:">
                    <el-date-picker  v-model="searchForm.startTime" format="yyyy-MM-dd HH:mm" type="datetime" placeholder="选择日期"></el-date-picker>
                </el-form-item>
                <el-form-item label="—" class="widthauto">
                    <el-date-picker  v-model="searchForm.endTime" format="yyyy-MM-dd HH:mm" type="datetime" placeholder="选择日期"></el-date-picker>
                </el-form-item>
                <el-form-item label="客户姓名:" prop="cusName">
                    <el-input v-model="searchForm.cusName" placeholder="客户姓名" class="input-with-select"></el-input>
                </el-form-item>
      				  <el-form-item label="电销组:" prop="teleGorupId">
        				    <el-select v-model="searchForm.teleGorupId" clearable @change="getSaleList" placeholder="电销组" filterable>
          				      <el-option
          					      v-for="item in teleGorupOptions"
          					      :key="item.id"
          					      :label="item.name"
          					      :value="item.id">
          					    </el-option>
        				    </el-select>
      				  </el-form-item>
      				  <el-form-item label="电销顾问:" prop="teleSaleId">
        				    <el-select v-model="searchForm.teleSaleId" clearable placeholder="电销顾问" filterable>
          				      <el-option
          					      v-for="item in teleSaleOptions"
          					      :key="item.id"
          					      :label="item.name"
          					      :value="item.id">
          					    </el-option>
        				    </el-select>
      				  </el-form-item>
                <el-row v-show="isShow">
                    <el-form-item label="邀约来访时间:">
                        <el-date-picker  v-model="searchForm.startReserveTime" format="yyyy-MM-dd HH:mm"  type="datetime" placeholder="选择日期"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="—" class="widthauto">
                        <el-date-picker  v-model="searchForm.endReserveTime" format="yyyy-MM-dd HH:mm"  type="datetime" placeholder="选择日期"></el-date-picker>
                    </el-form-item>
          				  <el-form-item label="考察项目:" prop="projectId">
            				    <el-select v-model="searchForm.projectId" clearable placeholder="考察项目" filterable>
              				      <el-option
              					      v-for="item in projectOptions"
              					      :key="item.id"
              					      :label="item.projectName"
              					      :value="item.id">
              					    </el-option>
            				    </el-select>
          				  </el-form-item>
            			  <el-form-item label="开店省份:" prop="province">
              			    <el-select v-model="searchForm.province" clearable  placeholder="开店省份">
                			      <el-option
                				      v-for="item in provinceOptions"
                				      :key="item.name"
                				      :label="item.name"
                				      :value="item.name">
                				    </el-option>
              			    </el-select>
            			  </el-form-item> 
            			  <!--  
            			  <el-form-item class="formItem"  prop="delFalg">
            			    <el-select v-model="searchForm.delFalg" clearable placeholder="邀约来访状态">
            			      <el-option
            				      v-for="item in delFalgOptions"
            				      :key="item.value"
            				      :label="item.name"
            				      :value="item.value">
            				  </el-option>
            			    </el-select>
            			  </el-form-item>
            			  -->
                </el-row>
                <div class="mainSearchBtnBox"> 
          			    <el-button icon="el-icon-search" type="primary" @click="searchTable()" class="searchBtn">搜索</el-button>
                    <!-- <el-button type="info" class="searchBtn">取消</el-button> -->
                    <span style="color: #5c6be8;cursor: pointer;margin:0 10px;" @click="toogleClick"><span v-if="isShow">收起</span><span v-else>展开更多</span><i :class="{'greycolor paddingL6 el-icon-arrow-up':isShow,'greycolor paddingL6 el-icon-arrow-down':!isShow}"></i></span>
                </div> 
          	</el-form>
        </div>
        <el-row>
            <el-table  ref="multipleTable" tooltip-effect="dark" border @row-dblclick="showCustomerDetail" @selection-change="handleSelectionChange" @row-click="clickRow" style="width: 100%"  :data="dataTable" @sort-change="sort_change">
                <el-table-column align="center" type="selection" label="全选" width="55"></el-table-column>
                <el-table-column align="center" type="index" label="序号" width="55"></el-table-column>
                <el-table-column align="center" prop="reserveTime" label="邀约来访时间" sortable :formatter="dateFormat" width="130"></el-table-column>
                <el-table-column align="center" prop="teleGorupName" label="电销组" width="100"></el-table-column>
                <el-table-column align="center" prop="teleDirectorName" label="电销总监" width="90"></el-table-column>
                <el-table-column align="center" prop="cusName" label="客户姓名" width="120"></el-table-column>
                <el-table-column align="center" prop="teleSaleName" label="电销顾问" width="90"></el-table-column>
                <el-table-column align="center" prop="accountPhone" label="电销顾问电话" width="100"></el-table-column>
                <el-table-column align="center" prop="teleProjectId" label="电销组项目"  width="100"></el-table-column>
                <el-table-column align="center" prop="tasteProjectId" label="考察项目" :formatter="transformProject" width="100"></el-table-column>
                <el-table-column align="center" prop="province" label="开店省份" width="80"></el-table-column>
                <el-table-column align="center" prop="city" label="开店城市" width="80"></el-table-column>
                <el-table-column align="center" prop="district" label="开店区／县" width="90"></el-table-column>
                <el-table-column align="center" prop="sex" label="客户性别" :formatter="transformSex" width="65"></el-table-column>
                <el-table-column align="center" prop="age" label="客户年龄" width="65"></el-table-column>
                <el-table-column align="center" prop="isInviteLetter" label="是否有邀请函" :formatter="transformLetter" width="95"></el-table-column>
                <el-table-column align="center" prop="hasAddress" label="选址情况" :formatter="transformAddress" width="80"></el-table-column>
                <el-table-column align="center" prop="advanceAmount" label="投资金额" :formatter="transformUssm" width="80"></el-table-column>
                <el-table-column align="center" prop="delFalg" label="邀约来访状态" :formatter="transformDelFalg" width="95"></el-table-column>

               <el-table-column align="center" prop="createTime" label="提交邀约时间" sortable :formatter="dateFormat" width="130"></el-table-column>
               <el-table-column align="center" prop="purType" label="意向品类" :formatter="transformPurProject" width="80"></el-table-column>
              <el-table-column align="center" prop="partnerType" label="合伙人" :formatter="transformPartner" width="70"></el-table-column>
               <el-table-column align="center" prop="hasExperience" label="餐饮经验" :formatter="transformExperience" width="80"></el-table-column>
               <el-table-column align="center" prop="area" label="店铺面积" :formatter="transformArea" width="80"></el-table-column>
              
               
               
            </el-table>
            <table-pagination v-if="paginationShow" :pager="pager" @change="searchTable"></table-pagination>
        </el-row>
    </div>
    <!-- dialog -->
    <el-dialog  title="分发资源"  :visible.sync="allocationVisible" width="540px">
        <template>
            <el-form :model="allocationForm" ref="allocationForm" :rules="allocationFormRules">
                <el-form-item>{{allocationForm.message}}</el-form-item>
                <el-form-item label="商务经理:"    
                	label-width="100px"  
                	prop="saleId"
                	:rules="[
                	 { required: true, message: '商务经理不能为空'},
                	]"
                	>
                    <el-select v-model="allocationForm.saleId" placeholder="组内商务经理姓名" style="width: 260px;margin-right: 10px;" filterable>
                        <el-option v-for="item in saleOptions" 
                        			:key="item.id" 
                        			:label="item.name" 
                        			:value="item.id">
                        </el-option>
                    </el-select>
                    <el-button type="text" @click="showSaleIdOther" size="mini">
                        <i v-if="!isSaleIdOther" class="el-icon-plus"/></i>
                        <i v-if="isSaleIdOther" class="el-icon-minus"/></i>
                        辅助经理
                    </el-button>
                </el-form-item>
                <el-form-item label="辅助商务经理:" label-width="100px" prop="" style="margin-bottom: 20px;" v-if="isSaleIdOther">
                    <el-select v-model="allocationForm.saleIdOther" placeholder="组内商务经理姓名" style="width: 260px;margin-right: 10px;" filterable>
                        <el-option v-for="item in saleOptions" :key="item.id" :label="item.name"
                                   :value="item.id"></el-option>
                    </el-select>
                    <p style="position: absolute;bottom: -25px;color: #f56c6c;">增加辅助商务经理后，签约后两个商务经理将平分业绩</p>
                </el-form-item>
                <el-form-item label="备注:"  label-width="100px"  prop="remark">
                   	<el-input type="textarea" v-model="allocationForm.remark" class="input-with-select" maxlength="200" style="width: 350px;" :rows="4" placeholder="输入分发备注"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" :disabled="submitDisable" @click="allocationClue('allocationForm')">提 交</el-button>
                <el-button  @click="allocationClueCancel('allocationForm')">取 消</el-button>
            </div>
        </template>
    </el-dialog>
    <!-- dialog -->
    <!-- dialog -->
    <el-dialog  title="外调经理"  :visible.sync="transferVisible" width="540px">
        <template>
            <el-form :model="transferForm" ref="transferForm" :rules="transferFormRules">
            	  <el-form-item >{{transferForm.message}}</el-form-item>
                <el-form-item label="商务经理:"    
                	label-width="100px" 
                	prop="saleId"
                	:rules="[
                	 { required: true, message: '商务经理不能为空'},
                	]"
                	>
                    <el-select v-model="transferForm.saleId" placeholder="外调经理姓名（所属大区-所属组）" style="width: 260px;margin-right: 10px;" filterable>
                        <el-option v-for="item in allSaleOptions" 
                        			:key="item.id" 
                        			:label="item.name" 
                        			:value="item.id">
                        </el-option>
                    </el-select>
                    <el-button type="text" @click="showTransferIdOther" size="mini">
                        <i v-if="!isTransferIdOther" class="el-icon-plus"/></i>
                        <i v-if="isTransferIdOther" class="el-icon-minus"/></i>
                        辅助经理
                    </el-button>
                </el-form-item>
                <el-form-item label="辅助商务经理:" label-width="100px" prop="" style="margin-bottom: 20px;" v-if="isTransferIdOther">
                    <el-select v-model="transferForm.transferIdOther" placeholder="外调经理姓名（所属大区-所属组）" style="width: 260px;margin-right: 10px;" filterable>
                        <el-option v-for="item in allSaleOptions" :key="item.id" :label="item.name"
                                   :value="item.id"></el-option>
                    </el-select>
                    <p style="position: absolute;bottom: -25px;color: #f56c6c;">增加辅助商务经理后，签约后两个商务经理将平分业绩</p>
                </el-form-item>
                <el-form-item label="备注:" label-width="100px" prop="remark">
			    	        <el-input type="textarea" v-model="transferForm.remark" class="input-with-select" maxlength="200" style="width: 350px;" :rows="4" placeholder="请输入外调备注"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" :disabled="submitDisable" @click="transferClue('transferForm')">提 交</el-button>
                <el-button  @click="transferClueCancel('transferForm')">取 消</el-button>
            </div>
        </template>
    </el-dialog>
    
     <!-- 标记取消-->
	  <el-dialog title="取消原因"    :visible.sync="cancelFormVisible" width="540px">
	    <el-form :model="cancelDigForm" ref="cancelDigForm" :rules="cancelRules">
	      <el-row>
	        <div class="marginB10" style="padding-left: 150px;">确认标记取消选中的邀约来访？</div>
	        <el-form-item label="取消原因：" :label-width="formLabelWidth1" prop="cancelReason">
	          <el-input type="textarea" :rows="3" v-model="cancelDigForm.cancelReason" autocomplete="off" maxlength="100" placeholder="100字" style="width: 80%;"></el-input>
	        </el-form-item>
	      </el-row>
	    </el-form>
	    <div slot="footer" class="dialog-footer">
	      <el-button type="primary" @click="submitCancelForm('cancelDigForm')">提 交</el-button>
	      <el-button @click="cancelFormVisible= false" >取 消</el-button>
	    </div>
	  </el-dialog>
    <!-- dialog -->
     
</div>
<!-- import common js-->
<div th:include="_footer_include :: #jsLib"></div>
</body>
<script th:inline="javascript">
var allSaleList=[[${allSaleList}]];//所有商务总监
var busSaleList=[[${busSaleList}]];//商务总监
var saleGroupList=[[${saleGroupList}]];//电销组
//可签约的项目
var projectList=[[${projectList}]];
//所有项目
var teleProjectList=[[${teleProjectList}]];
var provinceList=[[${provinceList}]];//省份
var optionAddressList=[[${optionAddressList}]];//选址情况
var partnerList=[[${partnerList}]];//合伙人
var cateringExperienceList=[[${cateringExperienceList}]];//餐饮经验
var storefrontAreaList=[[${storefrontAreaList}]];//店铺面积
var ussmList=[[${ussmList}]];//投资金额
var purTypeList = [[${purTypeList}]] // 意向品类
var clueVM = new Vue({
        el: '#clueManage',
        data: {
            isSaleIdOther:false,
            isTransferIdOther:false,
            paginationShow: false,
            cancelFormVisible:false,
            isShow:false,
    		searchForm: {
        		cusName: '',
        		teleGorupId: '',
        		teleSaleId: '',
        		projectId: '',
        		province: '',
        		delFalg: '',
        		startTime: '',
        		endTime: '',
        		startReserveTime: '',
        		endReserveTime: '',
        		sortField: '',
        		sortType: ''
            },
            allocationForm: {
            	saleId:'',
            	remark:'',
            	message:'',
                saleIdOther:'',//辅助商务经理
              },
              transferForm: {
            	saleId:'',
            	remark:'',
            	message:'',
                transferIdOther:'',//辅助商务经理
              },
              cancelDigForm:{
                  cancelReason:'',
                },
            dataTable:[],
            teleGorupOptions:saleGroupList,
            teleSaleOptions:[],
            projectOptions:projectList,
            provinceOptions:provinceList,
            delFalgOptions:[{
            	value:0,
            	name:"正常"
            },{
            	value:1,
            	name:"删除"
            },{
            	value:2,
            	name:"取消"
            }],
            saleOptions:busSaleList,
            allSaleOptions:allSaleList,
            submitDisable: false,
            allocationVisible: false,
            transferVisible: false,
            pager:{
                total: 0,
                currentPage: 1,
                pageSize: 20,
            },
            allocationFormRules: {
            	saleId: [
                    { required: true, message: '请选择商务经理', trigger: 'change' }
                ]
              },
            transferFormRules: {
            	saleId: [
                    { required: true, message: '请选择商务经理', trigger: 'change' }
                ]
              },
              cancelRules:{
                  cancelReason: [
                    { required: true, message: '请填写取消原因', trigger: 'blur' }
                  ]
                },
            multipleSelection:[],
            formLabelWidth: '150px',
            formLabelWidth1: '120px',
            storeForm: {
                cusName: '',
                teleGorupId: '',
                teleSaleId: '',
                projectId: '',
                province: '',
                delFalg: '',
                startTime: '',
                endTime: '',
                startReserveTime: '',
                endReserveTime: '',
                sortField: '',
                sortType: ''
            },
            storeId: '',
            scrollTop: 0,
        },
        methods: {
          submitCancel() {
            
          },
            showSaleIdOther(){
                if(this.isSaleIdOther){
                    this.isSaleIdOther=false;
                    // 清空辅助经理的值
                    this.allocationForm.saleIdOther="";
                }else{
                    this.isSaleIdOther=true;
                }
            },
            showTransferIdOther(){
                if(this.isTransferIdOther){
                    this.isTransferIdOther=false;
                    // 清空辅助经理的值
                    this.transferForm.transferIdOther="";
                }else{
                    this.isTransferIdOther=true;
                }
            },
            clickRow(row){//点击单行选中复选框
                this.$refs.multipleTable.toggleRowSelection(row)
            },
        	searchTable() {
                var param ={};
                var startTime = this.searchForm.startTime;
                var endTime = this.searchForm.endTime;
                var startReserveTime = this.searchForm.startReserveTime;
                var endReserveTime = this.searchForm.endReserveTime;
            	var vilad=false;
                if(startTime&&endTime&&startTime> endTime){
                	vilad=true;
                }
                if(startReserveTime&&endReserveTime&&startReserveTime> endReserveTime){
                	vilad=true;
                }
                if(vilad){
                	this.$message({
                        message: '开始时间不能大于结束时间',
                        type: 'warning'
                      });
                    return;
                }
                param.startTime = startTime;
                param.endTime = endTime;
                param.startReserveTime = startReserveTime;
                param.endReserveTime = endReserveTime;
                param.pageSize = this.pager.pageSize;
                param.pageNum = this.pager.currentPage;
                param.teleGorupId = this.searchForm.teleGorupId;
                param.teleSaleId = this.searchForm.teleSaleId;
                param.tasteProjectId = this.searchForm.projectId;
                param.cusName = this.searchForm.cusName;
                param.province = this.searchForm.province;
               
                //列表只查询正常数据，取消删除数据不查询
                //param.delFalg = this.searchForm.delFalg;
                param.delFalg =0;
                param.sortField = this.searchForm.sortField;
                param.sortType = this.searchForm.sortType;
                console.info(param);
                axios.post('/business/busAllocation/list', param)
                .then(function (response) {
                    var result =  response.data;
                    console.info(result);
                    var table=result.data;
                    clueVM.dataTable= table.data;
                    clueVM.pager.total =  table.total;
                    clueVM.pager.currentPage = table.currentPage;

                      // 取出存储的id
                    if(!clueVM.paginationShow){
                       if(clueVM.storeId){
                           clueVM.$nextTick(function(){
                              var storage = [];
                              clueVM.dataTable.forEach(function(item, index){
                                  if(item.clueId === clueVM.storeId ){
                                      storage.push(clueVM.dataTable[index]);
                                  }
                              })
                              clueVM.toggleSelection(storage);
                              clueVM.$el.querySelector('.el-table__body-wrapper').scrollTop = clueVM.scrollTop;
                          })
                      }
                    }else{
                      removeSessionStore ("busAllocationManagerStoreForm");
                      removeSessionStore ("busAllocationManagerOtherVal");
                    }
                    clueVM.paginationShow = true;
                    clueVM.storeForm = clueVM.searchForm;

                })
                .catch(function (error) {
                     console.log(error);
                });
                
              },
              toggleSelection(rows) { // table select 默认选中fn
                  if (rows) {
                      rows.forEach(row => {
                          this.$refs.multipleTable.toggleRowSelection(row,true);
                      });
                  } else {
                      this.$refs.multipleTable.clearSelection();
                  }
              },
              //选择行
              handleSelectionChange(val) {
                  this.multipleSelection = val;
              },
              handleSizeChange(val) {
                  //下拉框  每页 10,20条切换 调用
                     console.log(`每页 ${val} 条`);
                  this.pageSize = val;
                  this.initTableData(1);
               },
               handleCurrentChange(val) {
                   //点击 页码
                 console.log(`当前页: ${val}`);
                 this.initTableData(val);
               },

            //电销项目转换方法
            transformTeleProject(row, column, cellValue, index) {
                var text = "";
                if (teleProjectList && cellValue) {
                    var array = cellValue.split(",");
                    for (var i = 0; i < array.length; i++) {
                        for (var j = 0; j < teleProjectList.length; j++) {
                            if (array[i] == teleProjectList[j].id) {
                                if (i == 0) {
                                    text = teleProjectList[j].projectName;
                                } else {
                                    text = text + "," + teleProjectList[j].projectName;
                                }
                            }
                        }
                    }
                }
                return text;
            },
               //考察项目转换方法
               transformProject(row, column, cellValue, index) {
            	   var text="";
              	   if(projectList&&cellValue){
	            	   var array=cellValue.split(",");
	                   for(var i=0;i<array.length;i++){
	                	   for(var j=0;j<projectList.length;j++){
	 	                		if(array[i]==projectList[j].id){
	 	                			if(i==0){
		 	                			text=projectList[j].projectName;
	 	                			}else{
		 	                			text=text+","+projectList[j].projectName;
	 	                			}
	 	                		}
	 	                	}
	                	}
              	    }
                    return text;
               },
             //意向项目转换方法
               transformPurProject(row, column, cellValue, index) {
            	   var text="";
                 if (purTypeList) {
                   for (var i = 0; i < purTypeList.length; i++) {
                     if (row.purType == purTypeList[i].value) {
                       text = purTypeList[i].name;
                     }
                   }
                 }
                   return text;
               },
               //性别转换方法
               transformSex(row, column, cellValue, index) {
                 var text="";
                 if(cellValue=="1"){
                   text="男"
                 }else if(cellValue=="2"){
                   text="女"
                 }
                 return text;
               },
               //邀约状态转换方法
               transformDelFalg(row, column, cellValue, index) {
                 var text="";
                 if(cellValue=="0"){
                   text="正常"
                 }else if(cellValue=="1"){
                   text="已删除"
                 }else if(cellValue=="2"){
                   text="已取消"
                 }
                 return text;
               },
               //合伙人转换方法
               transformPartner(row, column, cellValue, index) {
             	  var text="";
             	  if(partnerList){
 	                  for(var i=0;i<partnerList.length;i++){
 	                		if(cellValue==partnerList[i].value){
 	                			text=partnerList[i].name;
 	                		}
 	                	}
             	  }
                   return text;
               },
               //选址情况转换方法
               transformAddress(row, column, cellValue, index) {
             	  var text="";
             	  if(optionAddressList){
 	                  for(var i=0;i<optionAddressList.length;i++){
 	                		if(cellValue==optionAddressList[i].value){
 	                			text=optionAddressList[i].name;
 	                		}
 	                	}
             	  }
                   return text;
               },
               //餐饮经验转换方法
               transformExperience(row, column, cellValue, index) {
             	  var text="";
             	  if(cateringExperienceList){
 	                  for(var i=0;i<cateringExperienceList.length;i++){
 	                		if(cellValue==cateringExperienceList[i].value){
 	                			text=cateringExperienceList[i].name;
 	                		}
 	                	}
             	  }
                   return text;
               },
               //店铺面积转换方法
               transformArea(row, column, cellValue, index) {
             	  var text="";
             	  if(storefrontAreaList){
 	                  for(var i=0;i<storefrontAreaList.length;i++){
 	                		if(cellValue==storefrontAreaList[i].value){
 	                			text=storefrontAreaList[i].name;
 	                		}
 	                	}
             	  }
                   return text;
               },
               //投资金额转换方法
               transformUssm(row, column, cellValue, index) {
             	  var text="";
             	  if(ussmList){
 	                  for(var i=0;i<ussmList.length;i++){
 	                		if(cellValue==ussmList[i].value){
 	                			text=ussmList[i].name;
 	                		}
 	                	}
             	  }
                   return text;
               },
                //是否有邀请函
                transformLetter(row, column, cellValue, index) {
                    var text="";
                    if(cellValue == "0"){
                        text="否"
                    }else if(cellValue == "1"){
                        text="是"
                    }
                    return text;
                },
               //日期数据格式化方法
               dateFormat( row, column, cellValue, index) {
                 if (cellValue == undefined) {
                    return "";
                 }
                 return moment(cellValue).format("YYYY-MM-DD HH:mm:ss");
               },
               //打开分发资源
               toAllocationClue() {
            	   this.allocationForm.message="";
            	   this.allocationForm.saleId = '';
            	   this.allocationForm.remark = '';
           	       var rows = this.multipleSelection;
            	   if(rows.length==0){
                       this.$message({
                          message: '请选择一条数据进行分发',
                          type: 'warning'
                        });
                       return;
                   }
            	   if(this.$refs['allocationForm']) {
                       this.$refs['allocationForm'].resetFields();
                      }
            	   var text="";
            	   for(var i=0;i<rows.length;i++){
                   	   var curRow = rows[i];
                       if(curRow.busSaleId){
                    	   text+="当前选择“"+curRow.cusName+"”已有之前服务商务经理"+curRow.busSaleName+",";
                       }
                   }
            	   if(text!=""){
	                   text+="请确认后分发客户。";
	                   this.allocationForm.message=text;
                   }
            	   
                   this.allocationVisible = true;
                   // 默认不显示辅助商务经理
                   this.isSaleIdOther=false;
                   // 清空辅助经理的值
                    this.allocationForm.saleIdOther="";
               },
               allocationClueCancel(formName){//分发资源取消
            	   this.$refs[formName].resetFields();
            	   this.allocationVisible = false;
               },
               allocationClue(formName){//分发资源
            	   
            	   this.$refs[formName].validate((valid) => {
            	          if (valid) {
                          var rows = this.multipleSelection;
                          var idList = [];
                          var clueIdList = [];
                          for(var i=0;i<rows.length;i++){
                            var curRow = rows[i];
                            idList.push(curRow.id);
                            clueIdList.push(curRow.clueId);
                          }
                          //分发
                          var param  = {};
                          param.type=1;
                          param.reqSource = 1;
                          param.idList=idList;
                          param.clueIdList=clueIdList;
                          param.busSaleId=this.allocationForm.saleId;
                          if(this.allocationForm.saleIdOther){
                            if(this.allocationForm.saleIdOther==this.allocationForm.saleId){
                                clueVM.$message({
                                   message: "辅助经理不能和商务经理相同",
                                   type: 'error'
                                }); 
                                return
                            }
                            param.busSale2Id=this.allocationForm.saleIdOther;
                          }                          
                          param.remark=this.allocationForm.remark;
                          clueVM.submitDisable=true;
                          axios.post('/business/busAllocation/busAllocationClue',param)
                          .then(function (response) {
                              var data =  response.data;
                              if(data.code=='0'){
                              	clueVM.$message({message:'分发成功',type:'success',duration:1000,onClose:function(){
                                clueVM.allocationVisible = false;
                                clueVM.submitDisable=false;
                              		clueVM.searchTable();
                          	    }});
                              }else if(data.code=='21917'){
                                  clueVM.$message({
                                      message: "资源已分发",
                                      type: 'error'
                                  });
                                  clueVM.submitDisable=false;
                                  clueVM.allocationVisible = false;
                                  clueVM.searchTable();
                              } else{
                              clueVM.$message({
                                message: "接口调用失败",
                                type: 'error'
                              }); 
                              clueVM.submitDisable=false;
                              }
                          })
                          .catch(function (error) {
                        	  clueVM.submitDisable=false;
                            console.log(error);
                          });
            	            //end
            	          } else {
            	            console.log('error submit!!');
            	            return false;
            	          }
            	    });
                 },// method end
               //打开外调经理
               toTransferClue() {
                	 this.transferForm.message = '';
                	 this.transferForm.saleId = '';
                	 this.transferForm.remark = '';
                	 
           	       var rows = this.multipleSelection;
            	   if(rows.length==0){
                       this.$message({
                          message: '请选择一条数据进行外调',
                          type: 'warning'
                        });
                       return;
                   }
            	   if(this.$refs['transferForm']) {
                       this.$refs['transferForm'].resetFields();
                      }
            	   var text="";
            	   for(var i=0;i<rows.length;i++){
                   	   var curRow = rows[i];
                       if(curRow.busSaleId){
                    	   text+="当前选择“"+curRow.cusName+"”已有之前服务商务经理"+curRow.busSaleName+",";
                       }
                   }
            	   if(text!=""){
	                   text+="请确认后分发客户。";
	                   this.allocationForm.message=text;
                   }
                   this.transferVisible = true;
                   this.isTransferIdOther=false;
                    // 清空辅助经理的值
                    this.transferForm.transferIdOther="";
               },
               transferClueCancel(formName){//外调经理取消
            	   this.$refs[formName].resetFields();
            	   this.transferVisible = false;
               },
               transferClue(formName){//外调经理
            	   this.$refs[formName].validate((valid) => {
            	          if (valid) {            	        	  
            	        	  var rows = this.multipleSelection;
                              var idList = [];
                              var clueIdList = [];
                              for(var i=0;i<rows.length;i++){
                           	   var curRow = rows[i];
                           			idList.push(curRow.id);
                           			clueIdList.push(curRow.clueId);
                              }
                           	  //外调
                           	  var param  = {};
                           	  param.type=2;
                          	  param.idList=idList;
                          	  param.clueIdList=clueIdList;
                              param.busSaleId=this.transferForm.saleId;
                              if(this.transferForm.transferIdOther){
                                if(this.transferForm.transferIdOther==this.transferForm.saleId){
                                    clueVM.$message({
                                       message: "辅助经理不能和商务经理相同",
                                       type: 'error'
                                    }); 
                                    return
                                }
                                param.busSale2Id=this.transferForm.transferIdOther;              
                              }                          	  
                          	  param.remark=this.transferForm.remark;
                              clueVM.submitDisable=true;
                              axios.post('/business/busAllocation/busAllocationClue',param)
                               .then(function (response) {
                                   var data =  response.data;
                                   if(data.code=='0'){
                                   	clueVM.$message({message:'外调成功',type:'success',duration:1000,onClose:function(){
                                       clueVM.transferVisible = false;
                                       clueVM.submitDisable=false;
                                   		clueVM.searchTable();
                               	    }});
                                   }else{
                                     clueVM.$message({
                                       message: "接口调用失败",
                                       type: 'error'
                                      }); 
                                      clueVM.submitDisable=false;
                                   }
                               })
                               .catch(function (error) {
                            	   clueVM.submitDisable=false;
                                 console.log(error);
                               });
            	            //end
            	          } else {
            	            console.log('error submit!!');
            	            return false;
            	          }
            	  });
            	   
                 },// method end
                 showCustomerDetail(row, column){ // 客户详情
                    // 存储选中信息--start
                    var clueId=row.clueId;  
                    setSessionStore("busAllocationManagerStoreForm", this.storeForm);
                    var otherVal = {
                        "currentPage": this.pager.currentPage,
                        "clueId": clueId,
                        "scrollTop": this.$el.querySelector('.el-table__body-wrapper').scrollTop
                    }
                    setSessionStore("busAllocationManagerOtherVal", otherVal);
                    // 存储选中信息--end  
                    // window.location.href='/bus/BusinessCustomer/viewCustomerInfo?clueId='+row.clueId;
                    window.location.href='/bus/BusinessCustomer/viewCustomerInfo?clueId='+clueId;
                 },
              //根据电销组查询电销总监
              getSaleList() {
            	  var param ={};
            	  param.orgId = this.searchForm.teleGorupId;
                  console.info(param);
                  axios.post('/business/busAllocation/getSaleList', param)
                  .then(function (response) {
                        var result =  response.data;
                        console.info(result);
                        var table=result.data;
                        clueVM.teleSaleOptions= table;
                  })
                  .catch(function (error) {
                       console.log(error);
                  });
              },
              //排序
              sort_change(column) {
            	  var sortField="";
            	  var sortType="";
                  if (column.prop === 'createTime') {
                	  sortField="a.create_Time";
                  } else if (column.prop === 'reserveTime') {
                	  sortField="a.reserve_Time";
                  }
                  if (column.order === 'descending') {
                  	sortType="desc";
                  } else if (column.order === 'ascending') {
                  	sortType="asc";
                  }
                  this.searchForm.sortField=sortField;
                  this.searchForm.sortType=sortType;
                  this.searchTable();
              },
              toogleClick(){
                if(this.isShow){
                    this.isShow=false
                }else{
                    this.isShow=true
                }          
              },
            //打开取消邀约对话框
              openCancelForm() {
                var rows = this.multipleSelection;
                if(rows.length==0){
                  this.$message({
                    message: '请选择邀约数据进行取消',
                    type: 'warning'
                  });
                  return;
                }
                if(this.$refs['cancelDigForm']) {
                  this.$refs['cancelDigForm'].resetFields();
                }
                this.cancelDigForm.cancelReason="";
                this.cancelFormVisible=true;
              },
              //取消邀约数据
              submitCancelForm(formName) {
                this.$refs[formName].validate((valid) => {
                  if (valid) {
                    var rows = this.multipleSelection;
                    if(rows.length==0){
                      this.$message({
                        message: '请选择邀约数据进行取消',
                        type: 'warning'
                      });
                      return;
                    }
                    var rowIds = [];
                    for(var i=0;i<rows.length;i++){
                      var curRow = rows[i];
                      rowIds.push(curRow.id);
                    }
                    var reason= clueVM.cancelDigForm.cancelReason;
                    this.$confirm('确定要取消选中的邀约来访吗？', '提示', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning'
                    }).then(() => {
                      //删除
                      var param  = {cancelIdList:rowIds,cancelReason:reason};
                      axios.post('/business/busAllocation/cancelAppiontment',param)
                      .then(function (response) {
                        var data =  response.data;
                        if(data.code=='0'){
                          clueVM.$message({message:'取消成功',type:'success',duration:1000,onClose:function(){
                              clueVM.cancelFormVisible=false;
                              clueVM.searchTable();
                            }});
                        }else{
                          clueVM.$message({
                            message: "接口调用失败",
                            type: 'error'
                          });
                        }
                      })
                      .catch(function (error) {
                        console.log(error);
                      })
                      .then(function () {

                      });
                    }).catch(() => {

                    });
                  } else {
                    console.log('error submit!!');
                    return false;
                  }
                });

              },//end
        },
        created(){
            console.info("create method");
            // 进入页面判断有是否有存储值
            if(!this.paginationShow){
                var storeVal = getSessionStore("busAllocationManagerStoreForm");
                var otherVal = getSessionStore("busAllocationManagerOtherVal");
                if(storeVal && otherVal){
                    this.searchForm = storeVal;
                    this.$set(this.pager,"currentPage",otherVal.currentPage);
                    this.storeId = otherVal.clueId;
                    this.scrollTop = otherVal.scrollTop;
                }
            };
            // 取页数存储
            var localVal=localStorage.getItem('allChangePageSize')?parseInt(localStorage.getItem('allChangePageSize')):'';
            if(localVal){this.pager.pageSize = localVal;}
            
            this.searchTable();
           
        },
        mounted(){
           console.info("mounted method");
           document.getElementById('clueManage').style.display = 'block';
        }
    })
    
</script>
</html>